package com.settlement.system.converter;

import com.alibaba.excel.converters.integer.IntegerStringConverter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.CellData;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.settlement.system.common.enums.WpTypeEnum;
import org.apache.commons.lang3.StringUtils;

import java.text.ParseException;

/**
 * @author author
 */
public class WpDeliveryTypeConvert extends IntegerStringConverter {

    @Override
    public Integer convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws ParseException {
        String value = cellData.getStringValue();
        if(!StringUtils.isEmpty(value)){
            return WpTypeEnum.DELIVERY_TYPE.getNoByName(value);
        }
        return null;
    }

    @Override
    public WriteCellData convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
        String typeName = WpTypeEnum.DELIVERY_TYPE.getNameByNo(value);
        if(!StringUtils.isEmpty(typeName)){
            return new WriteCellData(typeName);
        }
        return new WriteCellData();
    }
}
